package com.brillilab.starter.controller.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.brillilab.common.entity.ResponseVo;
import com.brillilab.common.utils.ValidatorUtil;
import com.brillilab.service.logic.message.MessageLogic;

/**
 * 邮件发送Controller
 *
 * @author wmh
 */
@RestController
@RequestMapping("/api/email")
public class EmailSendController {

	@Autowired
	private MessageLogic messageLogic;

	/**
	 * 发送邮箱验证码
	 * 
	 * @return
	 */
	@PostMapping("/emailCode")
	public ResponseVo sendValidateCode(@RequestBody JSONObject json){
		String email = json.getString("email");
		Assert.notNull(email,"请输入邮箱！");
		Assert.isTrue(ValidatorUtil.isEmail(email),"请输入正确格式的邮箱！");
		boolean b = messageLogic.sendEmailValidateCode(email);
		return b?ResponseVo.success():ResponseVo.failure("发送失败，请检查您的邮箱地址是否有误！");
	}
}
